#include <STC89C5xRC.H>
#include "i2c.h"

#define at24c02_address 0xa0


//at24c02写入一个字节到wordaddress地址
void at24c02_writebyte(unsigned char wordaddress,unsigned char Data)
{
	unsigned char ack;
	i2c_start();
	i2c_sendbyte(at24c02_address);
	ack = i2c_receiveack();
	i2c_sendbyte(wordaddress);
	ack = i2c_receiveack();
	i2c_sendbyte(Data);
	ack = i2c_receiveack();
	i2c_stop();
}

//at24c02读出wordaddress地址的一个字节
unsigned char at24c02_readbyte(unsigned char wordaddress)
{
	unsigned char Data,ack;
	i2c_start();
	i2c_sendbyte(at24c02_address);
	ack = i2c_receiveack();
	i2c_sendbyte(wordaddress);
	ack = i2c_receiveack();
	i2c_start();
	i2c_sendbyte(at24c02_address|0x01);
	ack = i2c_receiveack();
	Data=i2c_receivebyte();
	i2c_sendack(1);
	i2c_stop();
	
	
	return Data;
}